
cordova.define("com.mocoop.plugin.ajax.AjaxWorker", function(require, exports, module) {

    var exec = require('cordova/exec');

    /**
     * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
     * phone, etc.
     * @constructor
     */
    var AjaxWorker = {
        requestURL: function (url, requestData, type, options, callback) {
            var succeed = function (response) {
                if ((callback == undefined) || (callback == null)) {
                    return;
                }

                var returnedObjForCallback = new Object();
                returnedObjForCallback.result = true;
                returnedObjForCallback.response = response;
                callback(returnedObjForCallback);
            };
            var failed = function (error) {
                if ((callback == undefined) || (callback == null)) {
                    return;
                }

                var returnedObjForCallback = new Object();
                returnedObjForCallback.result = false;
                returnedObjForCallback.error = error;
                callback(returnedObjForCallback);
            };
            exec(succeed, failed, "AjaxWorker", "requestURL", [url, requestData, type, options]);
        }
    };

    /**
     * Get device info
     *
     * @param {Function} successCallback The function to call when the heading data is available
     * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
     */

    module.exports = AjaxWorker;

});

// 执行异步Ajax请求
function beginAsyncAjax(URL, requestData, method, callback, options) {
    //原生跨域请求
    navigator.AjaxWorker.requestURL(URL, requestData, method, options, callback);
}

